home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 14.2 KB | 484 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWInter.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCONTNT_H
- #include "FWContnt.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- #ifndef FWLNKSRC_H
- #include "FWLnkSrc.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWFrameworkContent
- #endif
-
- //========================================================================================
- // class FW_CDataInterchange
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange constructor
- //----------------------------------------------------------------------------------------
-
- FW_CDataInterchange::FW_CDataInterchange(Environment* ev, FW_CPart* part) :
- fPart(part),
- fLinkPromises(NULL),
- fClipboardPromise(NULL),
- fDragAndDropPromise(NULL)
- {
- FW_UNUSED(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange destructor
- //----------------------------------------------------------------------------------------
-
- FW_CDataInterchange::~FW_CDataInterchange()
- {
- FW_ASSERT(fLinkPromises == NULL); // Should be NULL by now
- FW_ASSERT(fClipboardPromise == NULL); // Should be NULL by now
- FW_ASSERT(fDragAndDropPromise == NULL); // Should be NULL by now
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::ExternalizeData
- //---------------------------------------------------------------------------------------
- // Note: Even if I am not an embedding part I still need to call BeginClone/EndClone
- // otherwise OpenDoc's OriginalCloneKind property in the draft is not set correctly
-
- void FW_CDataInterchange::ExternalizeData(Environment* ev,
- FW_CContent* content,
- FW_CFrame* scopeFrame,
- ODStorageUnit* destinationSU,
- FW_EStorageKinds storageKind,
- ODCloneKind cloneKind)
- {
- if (content == NULL)
- return;
-
- ODDraft* fromDraft = fPart->GetDraft(ev);
- ODDraft* dstDraft = destinationSU->GetDraft(ev);
-
- FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, cloneKind);
-
- cloneInfo.BeginClone(ev, dstDraft);
-
- PrivHandleExternalizeData(ev, content, destinationSU, storageKind, &cloneInfo);
-
- cloneInfo.EndClone(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivHandleExternalizeData
- //----------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivHandleExternalizeData(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* destinationSU,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- if (storageKind == FW_kClipboardStorage || storageKind == FW_kDragAndDropStorage)
- PrivDeletePromises(ev, storageKind);
-
- // ----- Add the needed properties first -----
- fPart->AddProperties(ev, destinationSU);
-
- content->Externalize(ev, destinationSU, storageKind, cloneInfo);
-
- // ----- If supported, write a shape property -----
- FW_CAcquiredODShape aqSelectionShape = content->CreateDataFrameShape(ev);
- if (((ODShape*)aqSelectionShape) != NULL)
- {
- // ----- Add the property. WriteShape will add the value
- if (destinationSU->Exists(ev, kODPropFrameShape, (ODValueType)NULL, 0))
- {
- destinationSU->Focus(ev, kODPropFrameShape,
- kODPosUndefined,
- (ODValueType)NULL,
- (ODValueIndex)1,
- kODPosUndefined);
- destinationSU->Remove(ev); // remove the first value
- }
- else
- destinationSU->AddProperty(ev, kODPropFrameShape);
-
- aqSelectionShape->WriteShape(ev, destinationSU);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::InternalizeData
- //---------------------------------------------------------------------------------------
- // Note: Even if I am not an embedding part I still need to call BeginClone/EndClone
- // otherwise OpenDoc's OriginalCloneKind property in the draft is not set correctly
-
- FW_EInternalizeResult FW_CDataInterchange::InternalizeData(Environment* ev,
- FW_CContent* content,
- FW_CFrame* scopeFrame,
- ODStorageUnit* sourceSU,
- FW_EStorageKinds storageKind,
- ODCloneKind cloneKind,
- ODPasteAsResult* embedAsInfo)
- {
- ODDraft* fromDraft = sourceSU->GetDraft(ev);
- ODDraft* dstDraft = fPart->GetDraft(ev);
-
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, cloneKind);
-
- if (embedAsInfo && embedAsInfo->mergeSetting == kODFalse)
- {
- result = PrivHandleEmbedAs(ev, content, sourceSU, &cloneInfo, embedAsInfo);
- }
- else
- {
- cloneInfo.BeginClone(ev, dstDraft);
-
- result = PrivHandleInternalizeData(ev, content, sourceSU, storageKind, &cloneInfo);
-
- if (result == FW_kInternalizeFailed)
- {
- cloneInfo.AbortClone(ev);
- return result;
- }
-
- cloneInfo.EndClone(ev);
-
- PrivPostInternalizeData(ev, content, &cloneInfo, result);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivPostInternalizeData
- //----------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivPostInternalizeData(Environment* ev,
- FW_CContent* content,
- FW_CCloneInfo* cloneInfo,
- FW_EInternalizeResult result)
- {
- FW_UNUSED(ev);
- FW_UNUSED(content);
- FW_UNUSED(result);
- FW_UNUSED(cloneInfo);
-
- // Nothing to do. See: FW_CEmbeddingDataInterchange::PrivPostInternalizeData
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivHandleInternalizeData
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CDataInterchange::PrivHandleInternalizeData(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* sourceSU,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
-
- FW_Boolean result = content->Internalize(ev, sourceSU, storageKind, cloneInfo);
- return result ? FW_kInternalizeContent : FW_kInternalizeFailed;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivHandleEmbedAs
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CDataInterchange::PrivHandleEmbedAs(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo,
- ODPasteAsResult* embedAsInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(content);
- FW_UNUSED(sourceSU);
- FW_UNUSED(cloneInfo);
- FW_UNUSED(embedAsInfo);
-
- FW_DEBUG_MESSAGE("FW_CDataInterchange::PrivHandleEmbedAs should never be called");
- return FW_kInternalizeFailed;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::ResolveClipboardPromise
- //----------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::ResolveClipboardPromise(Environment* ev)
- {
- if (fClipboardPromise == NULL)
- return;
-
- ODClipboard* clipboard = fPart->GetSession(ev)->GetClipboard(ev);
- ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
- if (clipboard->GetUpdateID(ev) == fClipboardPromise->GetUpdateID(ev))
- clipboardSU->ResolveAllPromises(ev);
- else
- PrivDeletePromises(ev, FW_kClipboardStorage);
-
- FW_ASSERT(fClipboardPromise == NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::ResolveAllPromises
- //----------------------------------------------------------------------------------------
- // Will resolve all promises (clipboard and all link promises)
-
- void FW_CDataInterchange::ResolveAllPromises(Environment* ev)
- {
- // ----- I should never have to resolve a drag and drop promise -----
- PrivDeletePromises(ev, FW_kDragAndDropStorage);
-
- // ----- resolve Clipboard promise -----
- ResolveClipboardPromise(ev);
-
- // ----- Resolve link promises -----
- if (fLinkPromises != NULL)
- {
- FW_CPromise* promise = fLinkPromises->First();
- while (promise != NULL)
- {
- FW_CPromise* next = fLinkPromises->After(promise);
- promise->PrivGetLinkSource(ev)->ResolveAllPromises(ev); // fLinkPromises might get deleted here
- promise = next;
- }
- }
-
- // ----- Should be NULL by now
- FW_ASSERT(fLinkPromises == NULL);
- FW_ASSERT(fClipboardPromise == NULL);
- FW_ASSERT(fDragAndDropPromise == NULL);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivDeletePromises
- //---------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivDeletePromises(Environment* ev, FW_EStorageKinds storageKind)
- {
- FW_UNUSED(ev);
- if (storageKind == FW_kClipboardStorage)
- {
- delete fClipboardPromise; // Will call PrivPromiseDeleted
- FW_ASSERT(fClipboardPromise == NULL);
- }
- else if (storageKind == FW_kDragAndDropStorage)
- {
- delete fDragAndDropPromise; // Will call PrivPromiseDeleted
- FW_ASSERT(fDragAndDropPromise == NULL);
- }
- else if (storageKind == FW_kLinkStorage)
- {
- if (fLinkPromises != NULL)
- {
- FW_CPromise* promise = fLinkPromises->First();
- while (promise != NULL)
- {
- FW_CPromise* next = fLinkPromises->After(promise);
- delete promise; // Will call PrivPromiseDeleted
- promise = next;
- }
-
- FW_ASSERT(fLinkPromises == NULL);
- }
- }
- else
- {
- FW_DEBUG_MESSAGE("FW_CDataInterchange::ResolveAllPromises - Unknown storageKind");
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivDeleteLinkPromises
- //---------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivDeleteLinkPromises(Environment* ev, FW_CLinkSource* linkSource)
- {
- if (fLinkPromises != NULL)
- {
- FW_TOrderedCollection<FW_CPromise> temp;
- FW_CPromise* promise; // %%% sfu
-
- FW_TOrderedCollectionIterator<FW_CPromise> ite(fLinkPromises);
- for (promise = ite.First(); ite.IsNotComplete(); promise = ite.Next())
- {
- if (promise->PrivGetLinkSource(ev) == linkSource)
- {
- temp.AddLast(promise);
- }
- }
-
- FW_TOrderedCollectionIterator<FW_CPromise> ite2(&temp);
- for (promise = ite2.First(); ite2.IsNotComplete(); promise = ite2.Next())
- {
- delete promise; // Will call PrivPromiseDeleted
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivPromise
- //----------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivPromise(Environment *ev,
- FW_CPromise* promise,
- ODStorageUnit* storageUnit,
- ODPropertyName propertyName,
- ODValueType valueType)
- {
- FW_ASSERT(propertyName != NULL);
- FW_ASSERT(valueType != NULL);
-
- storageUnit->Focus(ev, propertyName, kODPosUndefined, NULL, 0, kODPosUndefined);
-
- FW_CPromise* buffer = promise;
- FW_CByteArray bArray(&buffer, sizeof(FW_CPromise*));
- storageUnit->SetPromiseValue(ev,
- valueType,
- 0,
- bArray,
- fPart->GetODPart(ev));
-
- // ----- add the promise -----
- // Attention that a promise object can be promised multiple time
-
- FW_EStorageKinds storageKind = promise->GetStorageKind(ev);
-
- if (storageKind == FW_kLinkStorage)
- {
- if (fLinkPromises == NULL)
- fLinkPromises = FW_NEW(FW_TOrderedCollection<FW_CPromise>, ());
-
- if (!fLinkPromises->Contains(promise))
- fLinkPromises->AddLast(promise);
- }
- else if (storageKind == FW_kClipboardStorage)
- {
- FW_ASSERT(fClipboardPromise == NULL || fClipboardPromise == promise);
- fClipboardPromise = promise;
- }
- else if (storageKind == FW_kDragAndDropStorage)
- {
- FW_ASSERT(fDragAndDropPromise == NULL || fDragAndDropPromise == promise);
- fDragAndDropPromise = promise;
- }
- else
- {
- FW_DEBUG_MESSAGE("FW_CDataInterchange::ResolveAllPromises - Unknown storageKind");
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivPromiseDeleted
- //----------------------------------------------------------------------------------------
- // call by the destructor of FW_CPromise
-
- void FW_CDataInterchange::PrivPromiseDeleted(Environment *ev, FW_CPromise* promise)
- {
- FW_EStorageKinds storageKind = promise->GetStorageKind(ev);
-
- if (storageKind == FW_kLinkStorage)
- {
- FW_ASSERT(fLinkPromises != NULL);
- FW_ASSERT(fLinkPromises->Contains(promise));
-
- fLinkPromises->Remove(promise);
-
- if (fLinkPromises->Count() == 0)
- {
- delete fLinkPromises;
- fLinkPromises = NULL;
- }
- }
- else if (storageKind == FW_kClipboardStorage)
- {
- FW_ASSERT(fClipboardPromise == promise);
- fClipboardPromise = NULL;
- }
- else if (storageKind == FW_kDragAndDropStorage)
- {
- FW_ASSERT(fDragAndDropPromise == promise);
- fDragAndDropPromise = NULL;
- }
- else
- {
- FW_DEBUG_MESSAGE("FW_CDataInterchange::ResolveAllPromises - Unknown storageKind");
- }
- }
-
-